<template>
  <div class="head-box cenBet">
    <div class="head-left">
      <el-menu :default-active="activeIndex" mode="horizontal" @select="handleSelect" background-color="#313444" text-color="#9C9EAF" active-text-color="#00B2A9">
        <el-menu-item index="1">票务档案</el-menu-item>
        <!-- {{$store.state.router.thisRouterName}} -->
      </el-menu>
    </div>
    <div class="head-right">
      <el-select :disabled="$store.state.router.disabledSelectActivity" @change="changeActivityId()" style="width: 224px;height: 40px;" v-model="$store.state.activityId.thisActivityId" filterable placeholder="请选择">
        <el-option v-for="item in queryAll" :key="item.activity.activityId" :label="item.activity.title" :value="item.activity.activityId"></el-option>
      </el-select>
    </div>
  </div>
</template>
<script>
import service from "@/api/getActivityId";
import servicePub from "@/api/servicePub";
import testFiled from "./testFiled";
import shareUrls from "./shareUrls";
export default {
  data() {
    return {
      activeIndex: "1", //当前导航
      queryAll: [] //所有活动
    };
  },
  created() {
    this.initFun();
  },
  methods: {
    async initFun() {
      const { data = [] } = await service.queryAll();
      this.queryAll = data;
      if (data.length) {
        this.$store.state.activityId.thisActivityId = this.queryAll[0].activity.activityId;
        this.changeActivityId();
      }
      // 为了测试
      // this.$store.state.activityId.thisActivityId = 53; //39
      // this.changeActivityId();
      // 为了测试

      // this.sureThisPage();
    },
    // 确定当前页面
    sureThisPage() {
      // if (this.activeIndex == "1") {
      //   this.$store.state.router.thisRouterName = "";
      // }
      // if (this.activeIndex == "2") {
      //   this.$store.state.router.thisRouterName = "";
      // }
      // this.$router.push({
      //   name: this.$store.state.router.thisRouterName
      // });
    },
    //导航栏
    handleSelect(key, keyPath) {
      this.activeIndex = key;
      // this.sureThisPage();
    },
    // 活动变化时
    async changeActivityId() {
      // 当前活动报名表单字段
      this.$store.state.activityId.fieldList = [];
      const { data = {} } = await servicePub.queryModelList({
        activityId: this.$store.state.activityId.thisActivityId,
        start: 0,
        limit: 10,
        isPay: "free"
      });
      if (data.tempList.length && data.tempList[0].vnote1) {
        this.$store.state.activityId.fieldList = JSON.parse(
          data.tempList[0].vnote1
        );
        this.$store.state.activityId.fieldList.map(item => {
          item.attribute.filedValue = "";
        });
      }

      // console.log(testFiled);
      //  为了测试
      // this.$store.state.activityId.fieldList = JSON.parse(
      //   JSON.stringify(testFiled)
      // );
      // this.$store.state.activityId.fieldList.map(item => {
      //   item.attribute.filedValue = "";
      // });
      //  为了测试

      // 当前活动渠道来源(分享列表)
      this.$store.state.activityId.sourceList = [];
      const sourceList = await servicePub.queryShareUrlByChannelName({
        activityId: this.$store.state.activityId.thisActivityId,
        start: 0,
        isPay: "free",
        limit: 1000000000
      });
      console.log("sourceList", sourceList);
      this.$store.state.activityId.sourceList = sourceList.data.shareUrls || [];
      console.log("sourceList", this.$store.state.activityId.sourceList);
      // 为了测试
      // this.$store.state.activityId.sourceList = JSON.parse(
      //   JSON.stringify(shareUrls)
      // );
      // 为了测试
      // 渠道来源增加一个赠票的搜索条件
      this.$store.state.activityId.sourceList.push({
        channelName: "赠票",
        id: 6868686686868686
      });
      // console.log(this.$store.state.activityId.sourceList);
    }
  }
};
</script>


<style scoped>
.head-box {
  position: fixed;
  left: 0px;
  top: 0px;
  width: 100%;
  height: auto;
  min-height: 70px;
  z-index: 99;
  background: #313444;
  padding: 0px 38px;
}
.head-left,
.head-right {
  width: auto;
  height: 100%;
  margin: 0px;
  padding: 0px;
}
</style>
